<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core">

    <ui:composition template="layout.xhtml">
        <ui:define name="body">
            <h:form id="agenteForm" enctype="multipart/form-data">
                <br/>
                <h3 class="title">Pesquisando Micro Área</h3>
                <p:growl id="messages" showDetail="true" autoUpdate="true"  /> 
                <p:panel id="personPanel" style="background: none; border: none;" 
                         styleClass="container_24 clearfix both ">
                    <h4 class="title">Dados Gerais</h4>
                   
                    <p:outputLabel value="Nome :" styleClass="grid_3" for="nomeInputText" />
                    <p:inputText id="nomeInputText" styleClass="grid_8" 
                                 value="#{ managerPesquisarMicroArea.microArea.nome }" />
                    <div class="clear"/>
                    <p:outputLabel value="Código :" styleClass="grid_3" for="codigoInputText" />
                    <p:inputText id="codigoInputText" styleClass="grid_19"
                                 value="#{ managerPesquisarMicroArea.microArea.codigo }" />
                   
                </p:panel>
 

                <div class="buttonAction">
                    <p:commandButton id="pesquisarCommandButton" value="Pesquisar" icon="ui-icon-search"
                                     update="agenteTable" 
                                     actionListener="#{managerPesquisarMicroArea.pesquisar()}"
                                     />

                    <p:button href="index.xhtml" value="Cancelar"  icon="ui-icon-trash" />
                </div >

                <p:blockUI id="BLOCK" block="resultPanel" trigger="pesquisarCommandButton, agenteTable" > 
                    <p:graphicImage value="media/images/ajax-loader.gif"/>
                </p:blockUI> 


                <p:panel id="resultPanel" style="background: none; border: none;" 
                         styleClass="container_24 clearfix ">
                    <h4 class="title">Resultado</h4>

                    <p:dataTable id="agenteTable" var="item" value="#{managerPesquisarMicroArea.microAreas}" 
                                 styleClass="grid_24" rowIndexVar="rowid"                 
                                 rows="5" paginator="true" lazy="true"   
                                 paginatorTemplate="{FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
                                 currentPageReportTemplate="{currentPage} de {totalPages}"
                                 paginatorPosition="bottom" emptyMessage="Nenhum registro encontrado"
                                 style="white-space: pre-wrap;">

                        <f:facet name="header">
                            <p:outputLabel value="Profissional" />
                        </f:facet> 
                        <p:column headerText="Ação" width="100">
                            <p:button title="Editar"
                                      href="editarmicroarea.xhtml?editarMicroArea=#{item.id}"
                                      icon="ui-icon-pencil"/>
                            <p:button title="Visualizar"
                                      href="visualizarmicroarea.xhtml?visualizarMicroArea=#{item.id}"
                                      icon="ui-icon-zoomin"/> 
                            <p:commandButton update="@form" title="Excluir"
                                             oncomplete="dlg.show()" actionListener="#{managerPesquisarMicroArea.setRemoverMicroArea(item)}" 
                                             icon="ui-icon-trash">
                            </p:commandButton>


                        </p:column>

                        <p:column headerText="Nome">  
                            <h:outputText value="#{item.nome}" />
                           
                        </p:column>
                        <p:column headerText="Numero SUS">  
                            <h:outputText value="#{item.codigo}"/>
                        </p:column> 
                        <p:column headerText="Código">  
                            <h:outputText value="#{item.unidade.nome}"/>
                        </p:column> 

                    </p:dataTable> 

                </p:panel>
                  <p:dialog id="dlg" widgetVar="dlg" header="Remover Profissional" dynamic="true"
                          modal="true" appendToBody="false" resizable="false" width="50%" height="200px" draggable="false" closable="false">

                    <h4 class="title">Deseja Remover esse Registro ?</h4>
                    <div class="buttonAction">
                        <p:commandButton value="Sim" process="@this"  update=":agenteForm:agenteTable" 
                                         styleClass="ui-priority-primary" oncomplete="dlg.hide()"
                                         actionListener="#{managerPesquisarMicroArea.removerMicroArea()}"/>

                        <p:commandButton process=":agenteForm:agenteTable" oncomplete="dlg.hide()" value="Não" />
                    </div>


                </p:dialog>
                
            </h:form>
        </ui:define>
    </ui:composition>

</html>
